package presenters;

import model.ConnectionManager;
import model.DbSchema;
import model.IPresenter;
import views.AddCarPanel;

public class AddCarPresenter extends IPresenter {
	private AddCarPanel myPanel;
	
	public AddCarPresenter(AddCarPanel p) {
		super();
		myPanel = p;
	}
	
	public void addCar(String vin, String model, String type, String location,
			String color, String hourlyRate, String dailyRate, String seatingCap,
			String transmission, boolean bluetooth, boolean auxCable) {
		
		if(checkString(vin) && checkString2(model) && checkString(type) 
				&& checkString2(location) && checkString2(color) && checkString(hourlyRate)
				&& checkString(dailyRate) && checkString(seatingCap) && checkString(transmission)) {
			
			String sql = "INSERT INTO " + ConnectionManager.GROUP
					+ "." + DbSchema.CAR_TABLE + "("
					+ DbSchema.CAR_VIN 			+ ", "
					+ DbSchema.CAR_MODEL 		+ ", "
					+ DbSchema.CAR_HOURLY 		+ ", "
					+ DbSchema.CAR_DAILY 		+ ", "
					+ DbSchema.CAR_COLOR 		+ ", "
					+ DbSchema.CAR_TYPE 		+ ", "
					+ DbSchema.CAR_UNDER_MNTC 	+ ", "
					+ DbSchema.CAR_AUX 			+ ", "
					+ DbSchema.CAR_BLUETOOTH 	+ ", "
					+ DbSchema.CAR_TRANSMISSION + ", "
					+ DbSchema.CAR_CAPACITY 	+ ", "
					+ DbSchema.CAR_LOCATION 	+ ")"
					+ " VALUES('"
						+ vin 						+ "', '"
						+ model 					+ "', '"
						+ hourlyRate 				+ "', '"
						+ dailyRate 				+ "', '"
						+ color 					+ "', '"
						+ type 						+ "', '"
						+ "N" 						+ "', '"
						+ convertBool(auxCable) 	+ "', '"
						+ convertBool(bluetooth) 	+ "', '"
						+ transmission 				+ "', '"
						+ seatingCap 				+ "', '"
						+ location 					+ "');";
			
			int out = executeSQLUpdate(sql);
			System.out.println("Car added to row: " + out);
		}
	}
}
